﻿namespace WinKee
{
    using System;
    using System.Threading.Tasks;

    using Windows.ApplicationModel.Email;

    internal static class ErrorReporter
    {
        public async static Task ReportException(Exception ex)
        {
            var version = Windows.ApplicationModel.Package.Current.Id.Version;
            var versionString = string.Format(
                "{0}.{1}.{2}.{3}",
                version.Major,
                version.Minor,
                version.Build,
                version.Revision);

            ex = ex.GetBaseException();
            var body =
                string.Format(
                    "WinKee Exception Report\nException type: {0}\nException message: {1}\nException stack trace: {2}\nAdditional details:\nApplication version: {3}",
                    ex.GetType().Name,
                    ex.Message,
                    ex.StackTrace,
                    versionString);

            var objEmail = new EmailMessage
                               {
                                   Subject = "WinKee Error Report",
                                   Body = body
                               };

            objEmail.To.Add(new EmailRecipient("mar3ek@gmail.com"));

            await EmailManager.ShowComposeNewEmailAsync(objEmail);
        }
    }
}
